package managers.conversationManager;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import spotGUI.floatingChatGUI.FloatingChat;
import spotGUI.floatingChatGUI.FloatingChatFrame;
import utils.StackTracePrinter;

public class DefaultFloatingChatsManager implements FloatingChatsManager {

	private Map<Integer, FloatingChat> chats = Collections.synchronizedMap(new HashMap<Integer, FloatingChat>());

	
	
	
	
	public Map<Integer, FloatingChat> getChats() {
		return chats;
	}

	public void closeAllConnections (){
		Collection<FloatingChat> temp = chats.values();
		Iterator<FloatingChat> it  = temp.iterator();
		while (it.hasNext()) {
				try {
					it.next().getConversation().closeConnection();
				} catch (IOException e) {
					// do nothing
					StackTracePrinter.print(e);
				}
		}
	}

	public FloatingChat getChat (int user) {
		return chats.get(user);
	}
	
	public void addChat (int userId, FloatingChat frame) {
		chats.put(userId, frame);
	}

}
